package com.Nuyoah.demo01.mappers;

import com.Nuyoah.demo01.DTO.CommunityPageQry;
import com.Nuyoah.demo01.DTO.PostPageQry;
import com.Nuyoah.demo01.entity.Community;
import com.Nuyoah.demo01.entity.Post;
import com.Nuyoah.demo01.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface PostMapper {

    // 根据post_id查询帖子
    @Select("SELECT * FROM posts WHERE post_id = #{post_id}")
    Post getPostById(Integer post_id);
    // 查询所有帖子
    @Select("SELECT * FROM posts ORDER BY created_at DESC")
    List<Post> getAllPosts();
    // 插入帖子
    @Insert("INSERT INTO posts (user_id, title, content, created_at, updated_at, is_del) VALUES (#{user_id}, #{title}, #{content}, NOW(), NOW(), 0)")
    @Options(useGeneratedKeys = true, keyProperty = "post_id")
    Integer insertPost(Post post);
    // 更新帖子
    @Update("UPDATE posts SET title = #{title}, content = #{content}, updated_at = NOW() WHERE post_id = #{post_id}")
    Integer updatePost(Post post);
    // 删除帖子
    @Delete("DELETE FROM posts WHERE post_id = #{post_id}")
    Integer deletePost(Integer post_id);

    List<Post> selectPagePosts(PostPageQry qry);

    Integer likePost(Integer id);
}